$NG.AllReady(function (page, { useAction, useBeforeClick, useValuesChange, useClick, useUpdateRow, subscribe, useUpdateRows }) {
    const mstform = $NG.getCmpApi("p_form_ndczjhtz_m")
    const dgrid1 = $NG.getCmpApi("")
    const getHeadValue = (str) => mstform.getItem(str).getValue()

    hiddenHeadKey()

    if (page.oType == 'add') {
        mstform.getItem("u_nd").setValue({
            label: new Date().getFullYear(),
            value: new Date().getFullYear()
        })
    }

    useValuesChange(async () => {
        await getNdCjJhtjInfoByPhid()
    }, "p_form_ndczjhtz_m.u_ntmc")

    useValuesChange(() => {
        hiddenHeadKey()
    }, "p_form_ndczjhtz_m.u_sftz")



    // 获得合同信息
    async function getNdCjJhtjInfoByPhid() {
        const phid = getHeadValue("u_ntmc")
        if (!phid) return
        await $NG.execServer("getNdCjJhtjInfoByPhid", { phid }, (res) => {
            if (res.count == 0) return
            const datas = JSON.parse(res.data)[0].extendObjects
            const arr = [
                {
                    key: "u_sccyllb",
                    value: {
                        label: datas.sccyllb_name,
                        value: datas.sccyllb_phid
                    }
                },
                {
                    key: "u_ywlb",
                    value: {
                        value: datas.ywlb_phid,
                        label: datas.ywlb_name
                    }
                },
                {
                    key: "u_hylb",
                    value: {
                        label: datas.hylb_name,
                        value: datas.hylb_phid
                    }
                },
                {
                    key: "u_xmmc",
                    value: {
                        label: datas.xm_name,
                        value: datas.xm_phid,
                    }
                },
                {
                    key: "u_htje",
                    value: datas.u_htje
                },
                {
                    key: "u_jhkgrq",
                    value: datas.u_jhkgrq
                },
                {
                    key: "u_jhwgrq",
                    value: datas.u_jhwgrq
                }, {
                    key: "u_snwccz",
                    value: datas.u_snwccz
                },
                {
                    key: "u_snwcyysr",
                    value: datas.u_snwcyysr
                },
                {
                    key: "u_snmhtcl",
                    value: datas.u_snmhtcl
                },
                {
                    key: "u_bnyysrjh",
                    value: datas.u_bnyysrjh
                },
                {
                    key: "u_bnczjh",
                    value: datas.u_bnczjh
                },
                {
                    key: "u_zzssl",
                    value: datas.u_zzssl
                },
                {
                    key: "u_sgzt",
                    value: {
                        label: datas.sgzt_name,
                        value: datas.sgzt_phid
                    }
                },
                {
                    key: "u_yjwgrq",
                    value: datas.u_sjwgrq
                },
                {
                    key: "u_sjkgrq",
                    value: datas.u_sjkgrq
                }
            ]
            setHeadValue(arr)
        })
    }

    // 字段隐藏
    function hiddenHeadKey() {
        const u_sftz = mstform.getItem("u_sftz").getValue()
        let hidden = false
        if (u_sftz == "01") {
            hidden = true
        }
        mstform.getItem("u_tzyy").setProps({
            required: hidden
        })
    }

    // 赋值
    function setHeadValue(datas) {
        datas.forEach(item => {
            try {
                mstform.getItem(item.key).setValue(item.value)
            } catch (err) {
                console.log(`err`, err, item);
            }
        })
    }
})